<?php

namespace app\admin\model;

use think\Model;


class Avideo extends Model
{





    // 表名
    protected $name = 'avideo';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'status_text'
    ];
    protected static function init()
    {
        self::afterInsert(function ($row) {
            $pk = $row->getPk();
            $row->getQuery()->where($pk, $row[$pk])->update(['weigh' => $row[$pk]]);
        });
    }
    public function getTypeList()
    {
        return ['0' => __('Type 0'), '1' => __('Type 1'), '2' => __('Type 2')];
    }

    public function getStatusList()
    {
        return ['0' => __('Status 0'), '1' => __('Status 1'), '2' => __('Status 2'), '3' => __('Status 3')];
    }
    public function getShowStatusList()
    {
        return ['0' => __('ShowStatus 0'), '1' => __('ShowStatus 1')];
    }
    public function com()
    {
        return $this->hasMany('Comments','avideo_id','id');
    }

    public function exam()
    {
        return $this->hasOne('Exam','avideo_id','id');
    }

    public function category()
    {
        return $this->belongsTo('Category', 'cate_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }

    public function period()
    {
        return $this->belongsTo('Period', 'period_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }

    public function col()
    {
        return $this->belongsTo('Col', 'col_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }
}
